
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 09/21/2012 18:16:33
-- Generated from EDMX file: C:\Documents and Settings\asegovia\Escritorio\Proyectos\trunk\HelpDesk\TicketDeskBase\TicketDesk2\TicketDesk.Domain\Models\TicketDeskEntities.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [TicketDesk];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_TicketAttachments_Tickets]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[TicketAttachments] DROP CONSTRAINT [FK_TicketAttachments_Tickets];
GO
IF OBJECT_ID(N'[dbo].[FK_TicketComments_Tickets]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[TicketComments] DROP CONSTRAINT [FK_TicketComments_Tickets];
GO
IF OBJECT_ID(N'[dbo].[FK_TicketEventNotifications_TicketComments]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[TicketEventNotifications] DROP CONSTRAINT [FK_TicketEventNotifications_TicketComments];
GO
IF OBJECT_ID(N'[dbo].[FK_TicketTags_Tickets]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[TicketTags] DROP CONSTRAINT [FK_TicketTags_Tickets];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[AdCachedRoleMembers]', 'U') IS NOT NULL
    DROP TABLE [dbo].[AdCachedRoleMembers];
GO
IF OBJECT_ID(N'[dbo].[AdCachedUserProperties]', 'U') IS NOT NULL
    DROP TABLE [dbo].[AdCachedUserProperties];
GO
IF OBJECT_ID(N'[dbo].[Settings]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Settings];
GO
IF OBJECT_ID(N'[dbo].[TicketAttachments]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TicketAttachments];
GO
IF OBJECT_ID(N'[dbo].[TicketComments]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TicketComments];
GO
IF OBJECT_ID(N'[dbo].[TicketEventNotifications]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TicketEventNotifications];
GO
IF OBJECT_ID(N'[dbo].[Tickets]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Tickets];
GO
IF OBJECT_ID(N'[dbo].[TicketTags]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TicketTags];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'TicketAttachments'
CREATE TABLE [dbo].[TicketAttachments] (
    [TicketId] int  NULL,
    [FileId] int IDENTITY(1,1) NOT NULL,
    [FileName] nvarchar(255)  NOT NULL,
    [FileSize] int  NOT NULL,
    [FileType] nvarchar(250)  NOT NULL,
    [UploadedBy] nvarchar(100)  NOT NULL,
    [UploadedDate] datetime  NOT NULL,
    [FileContents] varbinary(max)  NOT NULL,
    [FileDescription] nvarchar(500)  NULL,
    [IsPending] bit  NOT NULL
);
GO

-- Creating table 'TicketComments'
CREATE TABLE [dbo].[TicketComments] (
    [TicketId] int  NOT NULL,
    [CommentId] int IDENTITY(1,1) NOT NULL,
    [CommentEvent] nvarchar(500)  NULL,
    [Comment] nvarchar(max)  NULL,
    [IsHtml] bit  NOT NULL,
    [CommentedBy] nvarchar(100)  NOT NULL,
    [CommentedDate] datetime  NOT NULL,
    [Version] binary(8)  NOT NULL
);
GO

-- Creating table 'TicketEventNotifications'
CREATE TABLE [dbo].[TicketEventNotifications] (
    [TicketId] int  NOT NULL,
    [CommentId] int  NOT NULL,
    [NotifyUser] nvarchar(100)  NOT NULL,
    [NotifyUserDisplayName] nvarchar(100)  NOT NULL,
    [NotifyEmail] nvarchar(255)  NOT NULL,
    [NotifyUserReason] nvarchar(50)  NOT NULL,
    [CreatedDate] datetime  NOT NULL,
    [DeliveryAttempts] int  NOT NULL,
    [LastDeliveryAttemptDate] datetime  NULL,
    [Status] nvarchar(20)  NOT NULL,
    [NextDeliveryAttemptDate] datetime  NULL,
    [EventGeneratedByUser] nvarchar(100)  NOT NULL
);
GO

-- Creating table 'Tickets'
CREATE TABLE [dbo].[Tickets] (
    [TicketId] int IDENTITY(1,1) NOT NULL,
    [Type] nvarchar(50)  NOT NULL,
    [Category] nvarchar(50)  NOT NULL,
    [Title] nvarchar(500)  NOT NULL,
    [Details] nvarchar(max)  NOT NULL,
    [IsHtml] bit  NOT NULL,
    [TagList] nvarchar(100)  NULL,
    [CreatedBy] nvarchar(100)  NOT NULL,
    [CreatedDate] datetime  NOT NULL,
    [Owner] nvarchar(100)  NOT NULL,
    [AssignedTo] nvarchar(100)  NULL,
    [CurrentStatus] nvarchar(50)  NOT NULL,
    [CurrentStatusDate] datetime  NOT NULL,
    [CurrentStatusSetBy] nvarchar(100)  NOT NULL,
    [LastUpdateBy] nvarchar(100)  NOT NULL,
    [LastUpdateDate] datetime  NOT NULL,
    [Priority] nvarchar(25)  NULL,
    [AffectsCustomer] bit  NOT NULL,
    [PublishedToKb] bit  NOT NULL,
    [Version] binary(8)  NOT NULL
);
GO

-- Creating table 'TicketTags'
CREATE TABLE [dbo].[TicketTags] (
    [TicketTagId] int IDENTITY(1,1) NOT NULL,
    [TagName] nvarchar(100)  NOT NULL,
    [TicketId] int  NOT NULL
);
GO

-- Creating table 'AdCachedRoleMembers'
CREATE TABLE [dbo].[AdCachedRoleMembers] (
    [GroupName] nvarchar(150)  NOT NULL,
    [MemberName] nvarchar(150)  NOT NULL,
    [MemberDisplayName] nvarchar(150)  NOT NULL
);
GO

-- Creating table 'AdCachedUserProperties'
CREATE TABLE [dbo].[AdCachedUserProperties] (
    [UserName] nvarchar(150)  NOT NULL,
    [PropertyName] nvarchar(100)  NOT NULL,
    [PropertyValue] nvarchar(250)  NULL,
    [LastRefreshed] datetime  NULL,
    [IsActiveInAd] bit  NOT NULL
);
GO

-- Creating table 'Settings'
CREATE TABLE [dbo].[Settings] (
    [SettingName] nvarchar(50)  NOT NULL,
    [SettingValue] nvarchar(max)  NULL,
    [DefaultValue] nvarchar(max)  NULL,
    [SettingType] nvarchar(50)  NOT NULL,
    [SettingDescription] nvarchar(max)  NULL
);
GO

-- Creating table 'Categoria'
CREATE TABLE [dbo].[Categoria] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Descripcion] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'Equipo'
CREATE TABLE [dbo].[Equipo] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [NumeroSerie] nvarchar(max)  NOT NULL,
    [CategoriaId] int  NOT NULL,
    [ModeloId] int  NOT NULL,
    [MarcaId] int  NOT NULL
);
GO

-- Creating table 'TipoSLA'
CREATE TABLE [dbo].[TipoSLA] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [DescripcionSLA] nvarchar(max)  NOT NULL,
    [TiempoRespuesta] smallint  NOT NULL
);
GO

-- Creating table 'Marca'
CREATE TABLE [dbo].[Marca] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Descripcion] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'Modelo'
CREATE TABLE [dbo].[Modelo] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Descripcion] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'IngresoBodega'
CREATE TABLE [dbo].[IngresoBodega] (
    [Id] int IDENTITY(1,1) NOT NULL
);
GO

-- Creating table 'Cliente'
CREATE TABLE [dbo].[Cliente] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [TipoSLAId] int  NOT NULL,
    [Nombre] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'Sucursal'
CREATE TABLE [dbo].[Sucursal] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Descripcion] nvarchar(max)  NOT NULL,
    [EmpresaId] int  NOT NULL,
    [ComunaId] int  NOT NULL,
    [Direccion] nvarchar(max)  NOT NULL,
    [ASPId] int  NOT NULL,
    [OpcionesId] int  NOT NULL,
    [MovimientoId] int  NOT NULL,
    [MovimientoId1] int  NOT NULL
);
GO

-- Creating table 'Comuna'
CREATE TABLE [dbo].[Comuna] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [RegionId] int  NOT NULL
);
GO

-- Creating table 'Region'
CREATE TABLE [dbo].[Region] (
    [Id] int IDENTITY(1,1) NOT NULL
);
GO

-- Creating table 'ASP'
CREATE TABLE [dbo].[ASP] (
    [Id] int IDENTITY(1,1) NOT NULL
);
GO

-- Creating table 'DespachoBodega'
CREATE TABLE [dbo].[DespachoBodega] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [NumeroFactura] nvarchar(max)  NOT NULL,
    [NumeroOrdenTransporte] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'Movimiento'
CREATE TABLE [dbo].[Movimiento] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [SucursalId] int  NOT NULL,
    [EquipoId] int  NOT NULL,
    [SucursalDestino_Id] int  NOT NULL
);
GO

-- Creating table 'OpcionesSA'
CREATE TABLE [dbo].[OpcionesSA] (
    [Id] int IDENTITY(1,1) NOT NULL
);
GO

-- Creating table 'DetalleXerox'
CREATE TABLE [dbo].[DetalleXerox] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [EquipoAsociado_Id] int  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [FileId] in table 'TicketAttachments'
ALTER TABLE [dbo].[TicketAttachments]
ADD CONSTRAINT [PK_TicketAttachments]
    PRIMARY KEY CLUSTERED ([FileId] ASC);
GO

-- Creating primary key on [TicketId], [CommentId] in table 'TicketComments'
ALTER TABLE [dbo].[TicketComments]
ADD CONSTRAINT [PK_TicketComments]
    PRIMARY KEY CLUSTERED ([TicketId], [CommentId] ASC);
GO

-- Creating primary key on [TicketId], [CommentId], [NotifyUser] in table 'TicketEventNotifications'
ALTER TABLE [dbo].[TicketEventNotifications]
ADD CONSTRAINT [PK_TicketEventNotifications]
    PRIMARY KEY CLUSTERED ([TicketId], [CommentId], [NotifyUser] ASC);
GO

-- Creating primary key on [TicketId] in table 'Tickets'
ALTER TABLE [dbo].[Tickets]
ADD CONSTRAINT [PK_Tickets]
    PRIMARY KEY CLUSTERED ([TicketId] ASC);
GO

-- Creating primary key on [TicketTagId] in table 'TicketTags'
ALTER TABLE [dbo].[TicketTags]
ADD CONSTRAINT [PK_TicketTags]
    PRIMARY KEY CLUSTERED ([TicketTagId] ASC);
GO

-- Creating primary key on [GroupName], [MemberName] in table 'AdCachedRoleMembers'
ALTER TABLE [dbo].[AdCachedRoleMembers]
ADD CONSTRAINT [PK_AdCachedRoleMembers]
    PRIMARY KEY CLUSTERED ([GroupName], [MemberName] ASC);
GO

-- Creating primary key on [UserName], [PropertyName] in table 'AdCachedUserProperties'
ALTER TABLE [dbo].[AdCachedUserProperties]
ADD CONSTRAINT [PK_AdCachedUserProperties]
    PRIMARY KEY CLUSTERED ([UserName], [PropertyName] ASC);
GO

-- Creating primary key on [SettingName] in table 'Settings'
ALTER TABLE [dbo].[Settings]
ADD CONSTRAINT [PK_Settings]
    PRIMARY KEY CLUSTERED ([SettingName] ASC);
GO

-- Creating primary key on [Id] in table 'Categoria'
ALTER TABLE [dbo].[Categoria]
ADD CONSTRAINT [PK_Categoria]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Equipo'
ALTER TABLE [dbo].[Equipo]
ADD CONSTRAINT [PK_Equipo]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'TipoSLA'
ALTER TABLE [dbo].[TipoSLA]
ADD CONSTRAINT [PK_TipoSLA]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Marca'
ALTER TABLE [dbo].[Marca]
ADD CONSTRAINT [PK_Marca]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Modelo'
ALTER TABLE [dbo].[Modelo]
ADD CONSTRAINT [PK_Modelo]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'IngresoBodega'
ALTER TABLE [dbo].[IngresoBodega]
ADD CONSTRAINT [PK_IngresoBodega]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Cliente'
ALTER TABLE [dbo].[Cliente]
ADD CONSTRAINT [PK_Cliente]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Sucursal'
ALTER TABLE [dbo].[Sucursal]
ADD CONSTRAINT [PK_Sucursal]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Comuna'
ALTER TABLE [dbo].[Comuna]
ADD CONSTRAINT [PK_Comuna]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Region'
ALTER TABLE [dbo].[Region]
ADD CONSTRAINT [PK_Region]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'ASP'
ALTER TABLE [dbo].[ASP]
ADD CONSTRAINT [PK_ASP]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'DespachoBodega'
ALTER TABLE [dbo].[DespachoBodega]
ADD CONSTRAINT [PK_DespachoBodega]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Movimiento'
ALTER TABLE [dbo].[Movimiento]
ADD CONSTRAINT [PK_Movimiento]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'OpcionesSA'
ALTER TABLE [dbo].[OpcionesSA]
ADD CONSTRAINT [PK_OpcionesSA]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'DetalleXerox'
ALTER TABLE [dbo].[DetalleXerox]
ADD CONSTRAINT [PK_DetalleXerox]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [TicketId] in table 'TicketAttachments'
ALTER TABLE [dbo].[TicketAttachments]
ADD CONSTRAINT [FK_TicketAttachments_Tickets]
    FOREIGN KEY ([TicketId])
    REFERENCES [dbo].[Tickets]
        ([TicketId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_TicketAttachments_Tickets'
CREATE INDEX [IX_FK_TicketAttachments_Tickets]
ON [dbo].[TicketAttachments]
    ([TicketId]);
GO

-- Creating foreign key on [TicketId] in table 'TicketComments'
ALTER TABLE [dbo].[TicketComments]
ADD CONSTRAINT [FK_TicketComments_Tickets]
    FOREIGN KEY ([TicketId])
    REFERENCES [dbo].[Tickets]
        ([TicketId])
    ON DELETE CASCADE ON UPDATE NO ACTION;
GO

-- Creating foreign key on [TicketId], [CommentId] in table 'TicketEventNotifications'
ALTER TABLE [dbo].[TicketEventNotifications]
ADD CONSTRAINT [FK_TicketEventNotifications_TicketComments]
    FOREIGN KEY ([TicketId], [CommentId])
    REFERENCES [dbo].[TicketComments]
        ([TicketId], [CommentId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [TicketId] in table 'TicketTags'
ALTER TABLE [dbo].[TicketTags]
ADD CONSTRAINT [FK_TicketTags_Tickets]
    FOREIGN KEY ([TicketId])
    REFERENCES [dbo].[Tickets]
        ([TicketId])
    ON DELETE CASCADE ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_TicketTags_Tickets'
CREATE INDEX [IX_FK_TicketTags_Tickets]
ON [dbo].[TicketTags]
    ([TicketId]);
GO

-- Creating foreign key on [CategoriaId] in table 'Equipo'
ALTER TABLE [dbo].[Equipo]
ADD CONSTRAINT [FK_CategoriaEquipo]
    FOREIGN KEY ([CategoriaId])
    REFERENCES [dbo].[Categoria]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_CategoriaEquipo'
CREATE INDEX [IX_FK_CategoriaEquipo]
ON [dbo].[Equipo]
    ([CategoriaId]);
GO

-- Creating foreign key on [ModeloId] in table 'Equipo'
ALTER TABLE [dbo].[Equipo]
ADD CONSTRAINT [FK_ModeloEquipo]
    FOREIGN KEY ([ModeloId])
    REFERENCES [dbo].[Modelo]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ModeloEquipo'
CREATE INDEX [IX_FK_ModeloEquipo]
ON [dbo].[Equipo]
    ([ModeloId]);
GO

-- Creating foreign key on [MarcaId] in table 'Equipo'
ALTER TABLE [dbo].[Equipo]
ADD CONSTRAINT [FK_MarcaEquipo]
    FOREIGN KEY ([MarcaId])
    REFERENCES [dbo].[Marca]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_MarcaEquipo'
CREATE INDEX [IX_FK_MarcaEquipo]
ON [dbo].[Equipo]
    ([MarcaId]);
GO

-- Creating foreign key on [TipoSLAId] in table 'Cliente'
ALTER TABLE [dbo].[Cliente]
ADD CONSTRAINT [FK_TipoClienteEmpresa]
    FOREIGN KEY ([TipoSLAId])
    REFERENCES [dbo].[TipoSLA]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_TipoClienteEmpresa'
CREATE INDEX [IX_FK_TipoClienteEmpresa]
ON [dbo].[Cliente]
    ([TipoSLAId]);
GO

-- Creating foreign key on [RegionId] in table 'Comuna'
ALTER TABLE [dbo].[Comuna]
ADD CONSTRAINT [FK_RegionComuna]
    FOREIGN KEY ([RegionId])
    REFERENCES [dbo].[Region]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_RegionComuna'
CREATE INDEX [IX_FK_RegionComuna]
ON [dbo].[Comuna]
    ([RegionId]);
GO

-- Creating foreign key on [EmpresaId] in table 'Sucursal'
ALTER TABLE [dbo].[Sucursal]
ADD CONSTRAINT [FK_EmpresaSucursal]
    FOREIGN KEY ([EmpresaId])
    REFERENCES [dbo].[Cliente]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_EmpresaSucursal'
CREATE INDEX [IX_FK_EmpresaSucursal]
ON [dbo].[Sucursal]
    ([EmpresaId]);
GO

-- Creating foreign key on [ComunaId] in table 'Sucursal'
ALTER TABLE [dbo].[Sucursal]
ADD CONSTRAINT [FK_ComunaSucursal]
    FOREIGN KEY ([ComunaId])
    REFERENCES [dbo].[Comuna]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ComunaSucursal'
CREATE INDEX [IX_FK_ComunaSucursal]
ON [dbo].[Sucursal]
    ([ComunaId]);
GO

-- Creating foreign key on [ASPId] in table 'Sucursal'
ALTER TABLE [dbo].[Sucursal]
ADD CONSTRAINT [FK_ASPSucursal]
    FOREIGN KEY ([ASPId])
    REFERENCES [dbo].[ASP]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ASPSucursal'
CREATE INDEX [IX_FK_ASPSucursal]
ON [dbo].[Sucursal]
    ([ASPId]);
GO

-- Creating foreign key on [OpcionesId] in table 'Sucursal'
ALTER TABLE [dbo].[Sucursal]
ADD CONSTRAINT [FK_OpcionesSucursal]
    FOREIGN KEY ([OpcionesId])
    REFERENCES [dbo].[OpcionesSA]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_OpcionesSucursal'
CREATE INDEX [IX_FK_OpcionesSucursal]
ON [dbo].[Sucursal]
    ([OpcionesId]);
GO

-- Creating foreign key on [SucursalId] in table 'Movimiento'
ALTER TABLE [dbo].[Movimiento]
ADD CONSTRAINT [FK_SucursalMovimientoDespacho]
    FOREIGN KEY ([SucursalId])
    REFERENCES [dbo].[Sucursal]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_SucursalMovimientoDespacho'
CREATE INDEX [IX_FK_SucursalMovimientoDespacho]
ON [dbo].[Movimiento]
    ([SucursalId]);
GO

-- Creating foreign key on [SucursalDestino_Id] in table 'Movimiento'
ALTER TABLE [dbo].[Movimiento]
ADD CONSTRAINT [FK_MovimientoSucursalRecepcion]
    FOREIGN KEY ([SucursalDestino_Id])
    REFERENCES [dbo].[Sucursal]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_MovimientoSucursalRecepcion'
CREATE INDEX [IX_FK_MovimientoSucursalRecepcion]
ON [dbo].[Movimiento]
    ([SucursalDestino_Id]);
GO

-- Creating foreign key on [EquipoId] in table 'Movimiento'
ALTER TABLE [dbo].[Movimiento]
ADD CONSTRAINT [FK_EquipoMovimiento]
    FOREIGN KEY ([EquipoId])
    REFERENCES [dbo].[Equipo]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_EquipoMovimiento'
CREATE INDEX [IX_FK_EquipoMovimiento]
ON [dbo].[Movimiento]
    ([EquipoId]);
GO

-- Creating foreign key on [EquipoAsociado_Id] in table 'DetalleXerox'
ALTER TABLE [dbo].[DetalleXerox]
ADD CONSTRAINT [FK_EquipoDetalleXerox]
    FOREIGN KEY ([EquipoAsociado_Id])
    REFERENCES [dbo].[Equipo]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_EquipoDetalleXerox'
CREATE INDEX [IX_FK_EquipoDetalleXerox]
ON [dbo].[DetalleXerox]
    ([EquipoAsociado_Id]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------